#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define getchar() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=getchar();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        x*=f;
    }
    char obuf[BUF],*p3=obuf;
    inline void pc(char ch){
        if(p3-obuf<BUF) *p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[32],ctop;
    template<typename T>inline void print(T x){
    	if(x<0) x=~x+1,pc('-');
        if(!x) return pc(48);
        while(x) ch[++ctop]=x%10^48,x/=10;
        while(ctop) pc(ch[ctop--]);
    }
    inline void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=5e5+5;
struct node{
	long long a,b;
	inline bool operator<(node y){return a*y.b<y.a*b;}
	inline void out(){
		long long gg=__gcd(a,b);
		print(a/gg),pc(' '),print(b/gg),pc('\n');
	}
};
int n,m,a[N],nxt[N],stk[N],top;
node t[N],mx[N];
int nxt1[N],nxt2[N];
inline void add(int x,node v){
	for(;x<=n&&t[x]<v;x+=x&-x) t[x]=v; 
}
inline node query(int x){
	node ans={0,1};
	for(;x;x-=x&-x) if(ans<t[x]) ans=t[x];
	return ans;
}
int r[N];
vector<int> Q[N];
node ans[N];
int main(){
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	read(n);
	for(int i=1;i<=n;++i) read(a[i]);
	nxt1[n+1]=nxt2[n+1]=n+1;
	for(int i=n;i;--i){
		if(a[i+1]>0) nxt1[i]=i+1;
		else nxt1[i]=nxt1[i+1];
		if(a[i+1]<0) nxt2[i]=i+1;
		else nxt2[i]=nxt2[i+1];
	}
	for(int i=1;i<=n;++i) t[i]={0,1},a[i]+=a[i-1];
	read(m);
	int ml=1e9,mr=0;
	for(int i=1,l;i<=m;++i){
		read(l),read(r[i]);
		Q[l].push_back(i);
		ml=min(ml,l);
		mr=max(mr,r[i]);
	}
	for(int i=n;i>=ml;--i){
		mx[i]={0,1};
		for(int j=i;j<=mr;j=nxt1[j]){
			int sum=a[j]-a[i-1];
			if(sum<0||a[j-1]-a[i-1]<0) break;
			node now={1ll*sum*sum,j-i+1};
			if(mx[j]<now) add(j,mx[j]=now);
		}
		for(int j=i;j<=mr;j=nxt2[j]){
			int sum=a[j]-a[i-1];
			if(sum>0||a[j-1]-a[i-1]>0) break;
			node now={1ll*sum*sum,j-i+1};
			if(mx[j]<now) add(j,mx[j]=now);
		}
		for(int j:Q[i]) ans[j]=query(r[j]);
	}
	for(int i=1;i<=m;++i) ans[i].out();
	flush();
	return 0;
}

